﻿using LoveEatRabbit.API.Read.Applications.Commands.Roles;
using LoveEatRabbit.Domain.RBAC;
using LoveEatRabbit.ErrorCode;
using LoveEatRabbit.Infrastructure.Interfaces;
using MediatR;

namespace LoveEatRabbit.API.Read.Applications.CommandHandlers.Roles
{
    public class RoleQueryCommandHandler : IRequestHandler<RoleQueryCommand, APIResult<List<RoleModel>>>
    {
        private readonly IBaseRespository<RoleModel> roleRep;

        public RoleQueryCommandHandler(IBaseRespository<RoleModel> roleRep)
        {
            this.roleRep = roleRep;
        }

        public Task<APIResult<List<RoleModel>>> Handle(RoleQueryCommand request, CancellationToken cancellationToken)
        {
            APIResult<List<RoleModel>> result=new APIResult<List<RoleModel>>();
            result.Code=APIResultCode.查询成功;
            result.Message=APIResultCode.查询成功.ToString();

            var res=roleRep.GetAll().ToList();
            result.Data=res;


            return Task.FromResult(result);
        }
    }
}
